<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .img {
            width: 500px;
            height: 300px;
        }
        .footer {
            width: 300px;
        }
        .footer span {
            display: inline-block;
            width: 26px;
            height: 26px;
            border-radius: 50%;
            background: orangered;
            margin-right: 40px;
        }

        .active {
            background: peru !important;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>
            <button  @click="delCount">----</button>
            <img class="img" :src="list[count]" alt="">
            <button @click="addCount">+++++</button>
            <div class="footer">
                <span v-for="(item, index) in list" :class="index === count?'active':''" @click="changeCount(index)">
                    {{ index + 1 }}
                </span>
            </div>
            <!-- <img class="img" v-for="item in list" :src="item" alt=""> -->
        </div>
    </div>

    <script src="./js/vue.js"></script>
    <script>
         const app = new Vue({
            el: "#app",
            data: {
                count: 0,
                list: [
                    "https://img1.baidu.com/it/u=1719063513,2559625643&fm=26&fmt=auto",
                    "https://img2.baidu.com/it/u=3666548066,2508071679&fm=26&fmt=auto",
                    "https://img2.baidu.com/it/u=1729250424,3321747351&fm=26&fmt=auto",
                    "https://img2.baidu.com/it/u=622902245,3661794572&fm=26&fmt=auto"
                ]
            },
            methods: {
                addCount() {
                    if (this.count >= this.list.length - 1) {
                        this.count = 0
                    } else {
                        this.count ++ 
                    }
                },
                delCount() {
                    if (this.count <= 0) {
                        this.count = this.list.length - 1
                    } else {
                        this.count --
                    }
                },
                changeCount(index) {
                    this.count = index
                }
            }
        })

    </script>
</body>
</html>